package com.ld.poetry.aigc.iflycode.gclu.unittest;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;
import java.util.List;

public class EmployeeServiceTest {

    private EmployeeService employeeService;

    @BeforeEach
    public void setUp() {
        employeeService = new EmployeeService();
    }

    @Test
    public void testAddEmployee_NormalCase() {
        EmployeeService.Employee employee = new EmployeeService.Employee("John", "IT");
        employeeService.addEmployee(employee);
        List<EmployeeService.Employee> employees = employeeService.getAllEmployees();
        assertEquals(1, employees.size());
        assertEquals("John", employees.get(0).getName());
        assertEquals("IT", employees.get(0).getDepartment());
    }

    @Test
    public void testAddEmployee_NullEmployee() {
        assertThrows(IllegalArgumentException.class, () -> {
            employeeService.addEmployee(null);
        });
    }

    @Test
    public void testGetAllEmployees() {
        EmployeeService.Employee employee1 = new EmployeeService.Employee("John", "IT");
        EmployeeService.Employee employee2 = new EmployeeService.Employee("Jane", "HR");
        employeeService.addEmployee(employee1);
        employeeService.addEmployee(employee2);
        List<EmployeeService.Employee> employees = employeeService.getAllEmployees();
        assertEquals(2, employees.size());
        assertEquals("John", employees.get(0).getName());
        assertEquals("IT", employees.get(0).getDepartment());
        assertEquals("Jane", employees.get(1).getName());
        assertEquals("HR", employees.get(1).getDepartment());
    }

    @Test
    public void testGetEmployeesByDepartment_NormalCase() {
        EmployeeService.Employee employee1 = new EmployeeService.Employee("John", "IT");
        EmployeeService.Employee employee2 = new EmployeeService.Employee("Jane", "HR");
        employee3 = new EmployeeService.Employee("Doe", "IT");
        employeeService.addEmployee(employee1);
        employeeService.addEmployee(employee2);
        employeeService.addEmployee(employee3);
        List<EmployeeService.Employee> employees = employeeService.getEmployeesByDepartment("IT");
        assertEquals(2, employees.size());
        assertEquals("John", employees.get(0).getName());
        assertEquals("IT", employees.get(0).getDepartment());
        assertEquals("Doe", employees.get(1).getName());
        assertEquals("IT", employees.get(1).getDepartment());
    }

    @Test
    public void testRemoveEmployee_NormalCase() {
        EmployeeService.Employee employee1 = new EmployeeService.Employee("John", "IT");
        EmployeeService.Employee employee2 = new EmployeeService.Employee("Jane", "HR");
        employeeService.addEmployee(employee1);
        employeeService.addEmployee(employee2);
        employeeService.removeEmployee(employee1);
        List<EmployeeService.Employee> employees = employeeService.getAllEmployees();
        assertEquals(1, employees.size());
        assertEquals("Jane", employees.get(0).getName());
        assertEquals("HR", employees.get(0).getDepartment());
    }
}